cmake_minimum_required(VERSION 3.8)

function(MakeProtocol PROTOSRC)
    file(GLOB_RECURSE PRJ_PROTO_FILES ${PROJECT_SOURCE_DIR}/${PROTOSRC}/*.proto)
    foreach(PROTOFILE ${PRJ_PROTO_FILES})
        message("Found Proto file: ${PROTOFILE}")
        STRING(REGEX MATCH "[^\\/]+\\.[protoPROTO]+" PROTONAME ${PROTOFILE})
        execute_process(COMMAND "protoc" "--proto_path=${PROJECT_SOURCE_DIR}/${PROTOSRC}" "--cpp_out=${PROJECT_SOURCE_DIR}/${PROTOSRC}/cpp" "${PROTONAME}"
                WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
                )
        message("protobuf compile file: ${PROTONAME}")
    endforeach()
endfunction(MakeProtocol PROTOSRC DESTDIR)

function(SearchIncludeDir SDIR)
    message("SEARCH in Dir::[${SDIR}] <<<<<<<<<<<<<<<<<<<<<<<<<<")
    file(GLOB_RECURSE PRJ_INC ${PROJECT_SOURCE_DIR}/${SDIR}/*.h)
    foreach(H_FULL_PATH ${PRJ_INC})
        message("found include file:${H_FULL_PATH}")
        STRING(REGEX MATCH ".*/" H_DIR_PATH ${H_FULL_PATH})
        message("add header path to include path: ${H_DIR_PATH}")
        include_directories(${H_DIR_PATH})
        #    link_directories(${H_DIR_PATH})
    endforeach(H_FULL_PATH ${PRJ_INC})
endfunction(SearchIncludeDir SDIR)
